﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Xml;
namespace GameVLTK
{
    public class NPC : UnMoveableUnit
    {
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="content"></param>
        /// <param name="path"></param>
        /// <param name="nTextures"></param>
        /// <param name="topLeft"></param>
        public NPC(ContentManager content, string path, int nTextures, Vector2 topLeft, string name)
        {
            this.Name = name;

            Texture2D[] textures;
            textures = new Texture2D[nTextures];

            int[] framSeq = new int[nTextures];
            for (int i = 0; i < nTextures; i++)
            {
                textures[i] = content.Load<Texture2D>(path + (i + 1).ToString("00"));
                framSeq[i] = i;
            }

            this.Sprites = new List<MySprite>();
            this.nSprites = 1;
            this.Size = new Vector2(textures[0].Width, textures[0].Height);
            this.TopLeft = topLeft;

            //Qui định thứ tự vẽ trên Map
            this.Z_Index = (float)this.TopLeft.Y;

            MySprite mySprite = new MySprite(textures, topLeft);
            mySprite.FrameSequence = framSeq;

            this.Sprites.Add(mySprite);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch);

            //Vẽ tên nhân vật
            Global.DrawName(spriteBatch, this.Name,
                                this.TopLeft, this.Size,Color.Yellow);
        }

        public override int OnEvent(Global.EVENTS eventID, object sender, object[] args)
        {
            int kq = 0;
            switch (eventID)
            {

                case Global.EVENTS.GM_MAP_TOPLEFT_CHANGED:
                    {
                        this.TopLeft += (Vector2)args[0];
                        break;
                    }
                default:
                    break;
            }

            return kq;
        }

    }
}
